Repository navigation
[POC] Login with Bitwarden consent and Agent Access handoff - #24837
JaredSnider-Bitwarden wants to merge 2 commits into
Conversation
🤖 Bitwarden Claude Code ReviewOverall Assessment: REQUEST CHANGES Reviewed the "Login with Bitwarden" proof of concept. It adds the web consent page, the static Code Review Details
|
| await this.agentConnectionApiService.post(new AgentConnectionRequest(connection)); | ||
|
|
||
| // Record consent via the API (mints a single-use token). No PSK is sent. | ||
| const { token } = await this.brokerApiService.postConsent(this.returnUrl); |
There was a problem hiding this comment.
postConsent (or anything after it) fails, the agent connection already created on the server is left behind, and each retry creates another one.
Details and fix
agentConnectionApiService.post(...) persists the wrapped PSK server-side before consent is recorded. The catch block only clears sessionStorage, so when postConsent or buildConsentCallbackUrl throws:
- a connection for this partner stays on the account even though no consent was granted
- that PSK was never delivered to the agent, so the connection is unusable
- clicking Approve again creates a second connection with a new PSK, and the duplicates then show up under "Connected apps" after the next sync
Either record consent before creating the connection, or keep the returned id and roll it back in the catch:
let createdId: string | undefined;
try {
// ...
const created = await this.agentConnectionApiService.post(new AgentConnectionRequest(connection));
createdId = created.id;
const { token } = await this.brokerApiService.postConsent(this.returnUrl);
// ...
} catch {
if (createdId != null) {
await this.agentConnectionApiService.delete(createdId).catch(() => {});
}
// existing error handling
}code-review
| return ( | ||
| parsed.hostname === "127.0.0.1" || | ||
| parsed.hostname === "localhost" || | ||
| parsed.hostname === "[::1]" | ||
| ); |
There was a problem hiding this comment.
🎨 SUGGESTED: isLoopback checks only the hostname, not the scheme, so a javascript://localhost/... URI would pass and run as script on the web vault origin.
Details and fix
For non-special schemes the WHATWG URL parser still fills in hostname from the //authority part, so new URL("javascript://localhost/%0a...").hostname === "localhost". Assigning that to window.location.href runs the payload in the vault origin. That origin can read sessionStorage, which is where the PSK is held.
The server is supposed to validate agentRedirectUri against the partner allow-list, but this function is documented as the client-side guard against leaking the secret. Pinning the scheme closes this whole class of attack with a single extra check:
return (
parsed.protocol === "http:" &&
(parsed.hostname === "127.0.0.1" ||
parsed.hostname === "localhost" ||
parsed.hostname === "[::1]")
);code-review
| const target = | ||
| `${agentRedirect}${separator}code=${encodeURIComponent(code)}&state=${encodeURIComponent(state)}` + | ||
| `#psk=${encodeURIComponent(psk)}`; | ||
| window.location.href = target; |
There was a problem hiding this comment.
Potential Cross Site Scripting (XSS) via window.location.href - medium severity
Using window.location.href or similar redirection methods with unvalidated user input can lead to cross-site scripting (XSS). If an attacker controls part of the URL, they may inject malicious scripts that execute in the victim’s browser, potentially allowing session hijacking, data theft, or other unauthorized actions. Proper validation and encoding of user-controlled values are required before using them in redirects or client-side navigation.
Show fix
Remediation: Avoid using window.location.href or similar redirection methods with unvalidated user input. Only allow redirects to trusted, predefined destinations or validate the input against a strict allowlist. When possible, use fixed URLs or server-side redirection logic, and ensure any user-controlled values are properly validated and encoded before use.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info
| * resumes the authorize request — issuing the code to the registered `redirect_uri` (the completion | ||
| * page). The plaintext PSK never leaves the client and is never sent to the Bitwarden server. | ||
| */ | ||
| // FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush |
There was a problem hiding this comment.
The OAuthAuthorizeComponent change-detection migration is marked FIXME; this unresolved marker leaves deferred work in production code.
Details
✨ AI Reasoning
The comment marks the component's change-detection migration as unfinished. A tracker link alone does not specify the remaining work or criteria for completion.
🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.
Reply on this comment to give feedback or ignore the issue.
More info
| @@ -0,0 +1,21 @@ | |||
| // FIXME: Update this file to be type safe and remove this and next line | |||
There was a problem hiding this comment.
The AgentConnectionStateProvider abstraction is marked FIXME for type-safety work; this unresolved marker leaves deferred work in production code.
Details
✨ AI Reasoning
The comment explicitly defers making the state provider abstraction type safe and provides no completion plan.
🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.
Reply on this comment to give feedback or ignore the issue.
More info
| @@ -0,0 +1,49 @@ | |||
| // FIXME: Update this file to be type safe and remove this and next line | |||
There was a problem hiding this comment.
The AgentConnectionView model is marked FIXME for type-safety work; this unresolved marker leaves deferred work in production code.
Details
✨ AI Reasoning
The comment explicitly defers making the view model type safe and provides no completion plan.
🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.
Reply on this comment to give feedback or ignore the issue.
More info
| @@ -0,0 +1,35 @@ | |||
| // FIXME: Update this file to be type safe and remove this and next line | |||
There was a problem hiding this comment.
The AgentConnectionStateProvider implementation is marked FIXME for type-safety work; this unresolved marker leaves deferred work in production code.
Details
✨ AI Reasoning
The comment explicitly defers making the state provider implementation type safe and provides no completion plan.
🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.
Reply on this comment to give feedback or ignore the issue.
More info
| @@ -0,0 +1,32 @@ | |||
| // FIXME: Update this file to be type safe and remove this and next line | |||
There was a problem hiding this comment.
The AgentConnectionData model is marked FIXME for type-safety work; this unresolved marker leaves deferred work in production code.
Details
✨ AI Reasoning
The comment explicitly defers making the data model type safe and provides no completion plan.
🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.
Reply on this comment to give feedback or ignore the issue.
More info
| @@ -0,0 +1,21 @@ | |||
| // FIXME: Update this file to be type safe and remove this and next line | |||
There was a problem hiding this comment.
The AgentConnectionRequest model is marked FIXME for type-safety work; this unresolved marker leaves deferred work in production code.
Details
✨ AI Reasoning
The comment explicitly defers making the request model type safe and provides no completion plan.
🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.
Reply on this comment to give feedback or ignore the issue.
More info
| * Revoking deletes the connection server-side (which pushes to the user's other clients) and from | ||
| * local state; the bot's short-lived token then expires on its own (no refresh). | ||
| */ | ||
| // FIXME(https://bitwarden.atlassian.net/browse/CL-764): Migrate to OnPush |
There was a problem hiding this comment.
The AgentConnectionsComponent change-detection migration is marked FIXME; this unresolved marker leaves deferred work in production code.
Details
✨ AI Reasoning
The comment marks the component's change-detection migration as unfinished. A tracker link alone does not specify the remaining work or criteria for completion.
🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.
Reply on this comment to give feedback or ignore the issue.
More info
| @@ -0,0 +1,77 @@ | |||
| // FIXME: Update this file to be type safe and remove this and next line | |||
There was a problem hiding this comment.
The AgentConnection model is marked FIXME for type-safety work; this unresolved marker leaves deferred work in production code.
Details
✨ AI Reasoning
The comment explicitly defers making the domain model type safe and provides no completion plan.
🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.
Reply on this comment to give feedback or ignore the issue.
More info
| @@ -0,0 +1,134 @@ | |||
| // FIXME: Update this file to be type safe and remove this and next line | |||
There was a problem hiding this comment.
The AgentConnectionService is marked FIXME for type-safety work; this unresolved marker leaves deferred work in production code.
Details
✨ AI Reasoning
The comment explicitly defers making the service type safe and provides no completion plan.
🔧 How do I fix it?
Address the issues mentioned in TODO/FIXME comments, create proper issue tickets for tracking, or remove outdated comments.
Reply on this comment to give feedback or ignore the issue.
More info
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #24837 +/- ##
========================================
Coverage 63.14% 63.14%
========================================
Files 4983 5019 +36
Lines 162261 162947 +686
Branches 26163 26275 +112
========================================
+ Hits 102452 102891 +439
- Misses 52844 53049 +205
- Partials 6965 7007 +42 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
🤖 Claude (AI) did this review and wrote these comments. I have not reviewed the findings myself yet.
The findings that integration tests prove are on the server PR, bitwarden/server#8944. The two comments here cover the completion connector and come from code reading; they are not tested.
Client-side items and open questions
Inline
- F5, vault side: the connector forwards the PSK to any process on the loopback port.
- Redirect model: the connector drops
issand does not forwarderror.
Not tested
- Key rotation re-encryption of agent connections, and the push types that sync connections to clients.
- The PSK generator is a stub that produces a random 256-bit value.
Open questions
- What does Agent Access pairing let a PSK holder do, and for how long?
- Must every client pair with the agent? Sync sends the PSK to every client. Pairing only the device that approved would reduce exposure.
| if (agentRedirect != null && isLoopback(agentRedirect)) { | ||
| const separator = agentRedirect.includes("?") ? "&" : "?"; | ||
| const target = | ||
| `${agentRedirect}${separator}code=${encodeURIComponent(code)}&state=${encodeURIComponent(state)}` + | ||
| `#psk=${encodeURIComponent(psk)}`; | ||
| window.location.href = target; |
There was a problem hiding this comment.
🤖 Found by Claude (AI). An integration test proves the server-side behavior. This connector code comes from code reading and is not tested.
F5, vault side · Medium (pending threat model). The connector forwards the plaintext PSK to the process that listens on the loopback address. The server side of F5 is on bitwarden/server#8944.
Details
- Identity accepts any loopback port for the agent redirect, so this forward cannot tell the real agent from another local process.
- The forward does not use the code exchange, so the partner's client secret does not protect the PSK.
isLoopbackacceptslocalhost, but the server allow-list rejects it. The two checks should agree (this side not tested).
| const error = params.get("error"); | ||
|
|
||
| if (error != null) { | ||
| showMessage(`Authorization failed: ${error}`); | ||
| return; | ||
| } |
There was a problem hiding this comment.
🤖 Found by Claude (AI) from code reading. Not tested.
Redirect model. The connector forwards only code and state to the agent. It drops iss, and on error it shows a message but sends nothing to the agent.
Details
- Discovery advertises
isssupport, so an RFC 9207 client MUST reject a forwarded response that has noiss(§2.4). - On
error, the agent gets no response.
Suggested fix: forward iss, and forward error and error_description to the agent redirect.
🎟️ Tracking
No ticket. This draft PR shows the
oauthproof-of-concept branch so that the team can review it together. Do not merge.Companion server PR: bitwarden/server#8944
📔 Objective
Add the web vault side of "Login with Bitwarden" for registered partner agents. The consent step also delivers an Agent Access pre-shared key to the agent.
AgentConnectionmodels, state, API service, sync and push handling, and a pre-shared key generator (currently a stub), with unit tests for the agent connection service.📸 Screenshots
None.